package test.core;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import hyl.core.MyFun;
import hyl.core.MyMath;
import hyl.core.fun.MyByte;

public class testBytes {
	@Test
	public void atest() {
		int i=(9 / 2) + (9 % 2 == 0 ? 0 : 1);
		System.out.println(i);
		int j=1+ 7 % 2 == 0 ? 0 : 1;
		System.out.println(j);
		int z=MyMath.ceilDiv(9, 2);
		System.out.println(z);
		int k=9 / 2 ;
		
		System.out.println(k);
	
	}
	// @Test
	public void test() {
		byte[] bb = MyFun.int2ByteArray(12);
		bb = new byte[] { 1, 2, 3, 4 };
		String s;
		System.out.println(MyByte.bytesToHex(bb));
		System.out.println(MyByte.bytesToBin(bb));
		s = MyByte.bytesToBin(bb);
		System.out.println(" 2 " + s);
		bb = MyByte.binToBytes(s);
		s = MyByte.bytesToBin(bb);
		System.out.println(" 3 " + s);

		byte[] cc = MyByte.binToBytes("00000001 00000010 00000011 00000100", ' ');
		s = MyByte.bytesToBin(cc, ' ');
		System.out.println("  " + s);
		cc = MyByte.binToBytes(s, ' ');
		MyByte.xorBit(cc, 5);
		s = MyByte.bytesToBin(cc, ' ');
		System.out.println("  " + s);
		MyByte.xorBit(cc, 5);
		s = MyByte.bytesToBin(cc, ' ');
		System.out.println("  " + s);
		System.out.println(MyByte.getBit(cc, 24));

		// System.out.println(MyByte.bytes2Hexstr(bb));
		// System.out.println(MyByte.bytesToHexStr(bb));
		long n = MyFun.getNs();
		for (int i = 0; i < 10000; i++) {
			s = MyByte.bytesToHex(bb);
		}
		System.out.println(MyFun.getNs() - n);
		n = MyFun.getNs();
		for (int i = 0; i < 10000; i++) {
			s = MyByte.bytesToBin(bb);
		}
		System.out.println(MyFun.getNs() - n);

//		n = MyFun.getNs();
//		for (int i = 0; i < 10000; i++) {
//			s = MyByte.bytes2Hexstr(bb);
//		}
//		System.out.println(MyFun.getNs() - n);
//		n = MyFun.getNs();
//		for (int i = 0; i < 10000; i++) {
//			s = MyByte.bytesToHexStr(bb);
//		}
//		System.out.println(MyFun.getNs() - n);

	}

	// @Test
	public void fun1_1() {
		byte[] arr = "等2144sd呢看不".getBytes();
		byte[] key = "sd呢".getBytes();
		System.out.println(MyByte.search(arr, 0, key));
		System.out.println(MyByte.leftLike(arr, key));

	}
	//@Test
	public void fun1_2() {
		int size=10;
		byte[][] bb = new byte[size][];
		for (int i = 0; i < size; i++) {
			String s= MyFun.getUUID();
			System.out.println("前" + i +s);
			bb[i] = s.getBytes();
			
		}
		
		byte[] bb1 = MyByte.packBytes(bb);
		byte[][] bb2 = MyByte.parseBytes(bb1);
		for (int i = 0; i < size; i++) {
			String s=MyFun.bytes2U8str(bb2[i]);
			System.out.println("后" + i +s);
	
		}
	
	}
	@Test
	public void fun1_2_2() {
		int size=2;
		List<byte[]> bb = new ArrayList<byte[]>();
		for (int i = 0; i < size; i++) {
			String s= MyFun.getUUID();
			System.out.println("前" + i +s);
			bb.add(s.getBytes()) ;
			
		}
	
		byte[] bb1 = MyByte.packBytes(bb);
		List<byte[]> bb2 = MyByte.parseBytes2(bb1);
		for (int i = 0; i < size; i++) {
			String s=MyFun.bytes2U8str(bb2.get(i));
			System.out.println("后" + i +s);
	
		}
		
	}
	@Test
	public void fun1_3_1() {
		int size=100000;
		byte[][] bb = new byte[size][];
		for (int i = 0; i < size; i++) {
			String s= MyFun.getUUID();
			//System.out.println("前" + i +s);
			bb[i] = s.getBytes();
			
		}
		long t=MyFun.getNs();
		byte[] bb1 = MyByte.packBytes(bb);
		byte[][] bb2 = MyByte.parseBytes(bb1);
//		for (int i = 0; i < size; i++) {
//			String s=MyFun.bytes2U8str(bb2[i]);
//			//System.out.println("后" + i +s);
//	
//		}
		long t2=MyFun.getNs()-t;
		System.out.println("aa:"+t2);
	}
	
	@Test
	public void fun1_3_2() {
		int size=100000;
		List<byte[]> bb = new ArrayList<byte[]>();
		for (int i = 0; i < size; i++) {
			String s= MyFun.getUUID();
			//System.out.println("前" + i +s);
			bb.add(s.getBytes()) ;
			
		}
		long
		 t=MyFun.getNs();
		byte[] bb1 = MyByte.packBytes(bb);
		List<byte[]> bb2 = MyByte.parseBytes2(bb1);
//		for (int i = 0; i < size; i++) {
//			String s=MyFun.bytes2U8str(bb2.get(i));
//			//System.out.println("后" + i +s);
//	
//		}
		long t2=MyFun.getNs()-t;
		System.out.println("bb:"+t2);
	}
}
